<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>第二十章：SpringBoot项目中使用WebSocket配置广播式通信 | 恒宇少年De成长之路</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="WebSocket为浏览器和服务端提供了双工异步通信的功能，浏览器可以向服务端发送消息，服务端也可以向浏览器发送消息。WebSocket需要浏览器的支持，目前大多数主流的浏览器都是支持的。 WebSocket是通过socket来实现双工异步通信能力的。但是直接使用WebSocket协议开发程序闲的特别繁琐，一般情况我们使用STOMP来实现交互。 SpringBoot在tomcat7内嵌版本就已经开">
<meta name="keywords" content="SpringBoot">
<meta property="og:type" content="article">
<meta property="og:title" content="第二十章：SpringBoot项目中使用WebSocket配置广播式通信">
<meta property="og:url" content="http://blog.yuqiyu.com/spring-boot-chapter-20/index.html">
<meta property="og:site_name" content="恒宇少年De成长之路">
<meta property="og:description" content="WebSocket为浏览器和服务端提供了双工异步通信的功能，浏览器可以向服务端发送消息，服务端也可以向浏览器发送消息。WebSocket需要浏览器的支持，目前大多数主流的浏览器都是支持的。 WebSocket是通过socket来实现双工异步通信能力的。但是直接使用WebSocket协议开发程序闲的特别繁琐，一般情况我们使用STOMP来实现交互。 SpringBoot在tomcat7内嵌版本就已经开">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-bf669f6eaa1e1d3b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2ddb2b2c338e41f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-4b0d53de49c4265e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-a9b815556013a337.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-0c3e6219786b2820.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-fcfe7a10ddac042d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-3c42e8557dca6cdd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-4290ed5258605b0b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-1d9b2e74c24f5220.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-c6c742af17e7d6e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-08e754419b7d3df1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2d947f30446934d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-4ef84278d49b1e6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-9424f9da4d78b115.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2026cbd6df94c079.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-cbc8a09b2d40773e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-5a8200485b1f4901.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-5019bdb93a5034b4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-5011800d54eef813.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-11eeff2cc0b0e701.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-2e3ece62d204b1cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-02-21T07:55:08.213Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="第二十章：SpringBoot项目中使用WebSocket配置广播式通信">
<meta name="twitter:description" content="WebSocket为浏览器和服务端提供了双工异步通信的功能，浏览器可以向服务端发送消息，服务端也可以向浏览器发送消息。WebSocket需要浏览器的支持，目前大多数主流的浏览器都是支持的。 WebSocket是通过socket来实现双工异步通信能力的。但是直接使用WebSocket协议开发程序闲的特别繁琐，一般情况我们使用STOMP来实现交互。 SpringBoot在tomcat7内嵌版本就已经开">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/4461954-bf669f6eaa1e1d3b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
    

    
        <link rel="alternate" href="/" title="恒宇少年De成长之路" type="application/atom+xml" />
    

    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">

    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">恒宇少年De成长之路</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/.">首页</a>
                
                    <a class="main-nav-link" href="/archives">时间轴</a>
                
                    <a class="main-nav-link" href="/categories">文章专题</a>
                
                    <a class="main-nav-link" href="/tags">标签云</a>
                
                    <a class="main-nav-link" href="/about">关于我</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/css/images/avatar.png" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <!--button type="submit" class="search-form-submit"></button-->
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td ><a  class="main-nav-link" href="/.">首页</a></td>
                
                    <td ><a  class="main-nav-link" href="/archives">时间轴</a></td>
                
                    <td ><a  class="main-nav-link" href="/categories">文章专题</a></td>
                
                    <td ><a  class="main-nav-link" href="/tags">标签云</a></td>
                
                    <td ><a  class="main-nav-link" href="/about">关于我</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/css/images/avatar.png" />
            <h2 id="name">恒宇少年</h2>
            <h3 id="title">Java软件工程师 &amp; 程序猿</h3>
            <span id="location"><i class="fa fa-map-marker"></i>山东, 济南</span>
            <a id="follow" target="_blank" href="https://www.jianshu.com/u/092df3f77bca">关注我</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                43
                <span>文章</span>
            </div>
            <div class="article-info-block">
                2
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="http://github.com/ppoffice/hexo-theme-icarus" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="twitter" class=tooltip>
                            <i class="fa fa-twitter"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="facebook" class=tooltip>
                            <i class="fa fa-facebook"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="dribbble" class=tooltip>
                            <i class="fa fa-dribbble"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="rss" class=tooltip>
                            <i class="fa fa-rss"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-spring-boot-chapter-20" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            第二十章：SpringBoot项目中使用WebSocket配置广播式通信
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/spring-boot-chapter-20/">
            <time datetime="2017-04-26T16:00:00.000Z" itemprop="datePublished">2017-04-27</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/SpringBoot/">SpringBoot</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
            <p><code>WebSocket</code>为浏览器和服务端提供了双工异步通信的功能，浏览器可以向服务端发送消息，服务端也可以向浏览器发送消息。<code>WebSocket</code>需要浏览器的支持，目前大多数主流的浏览器都是支持的。</p>
<p>WebSocket是通过socket来实现双工异步通信能力的。但是直接使用WebSocket协议开发程序闲的特别繁琐，一般情况我们使用STOMP来实现交互。</p>
<p><code>SpringBoot</code>在<code>tomcat7</code>内嵌版本就已经开始支持了WebSocket的支持，配置源码存在于<code>org.springframework.boot.autoconfigure.websocket</code>下，接下来我们来讲解<code>SpringBoot</code>项目如何配置使用<code>WebSocket</code>。<br><a id="more"></a></p>
<h1 id="本章目标"><a href="#本章目标" class="headerlink" title="本章目标"></a>本章目标</h1><p>SpringBoot项目配置使用WebSocket实现广播式消息。</p>
<h1 id="构建项目"><a href="#构建项目" class="headerlink" title="构建项目"></a>构建项目</h1><p>我们使用IntelliJ IDEA工具创建一个SpringBoot项目，并添加Jsp、Web、WebSocket等依赖，如下图1所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-bf669f6eaa1e1d3b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图1"></p>
<h1 id="配置WebSocket"><a href="#配置WebSocket" class="headerlink" title="配置WebSocket"></a>配置WebSocket</h1><p>下面我们创建一个WebSocketConfig配置类，添加SpringBoot项目对WebSocket的支持配置，如下图2所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2ddb2b2c338e41f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图2"></p>
<p>如上图2所示，我们通过@EnableWebSocketMessageBroker注解开启使用STOMP协议来传输消息，并且实现了registerStompEndpoints方法添加了对应的STOMP使用SockJS协议。接下来我们配置两个实体用于浏览器与服务器端的通信交互。</p>
<h4 id="浏览器向服务端发送消息实体"><a href="#浏览器向服务端发送消息实体" class="headerlink" title="浏览器向服务端发送消息实体"></a>浏览器向服务端发送消息实体</h4><p>我们创建一个简单的WiselyMessage实体，用于浏览器向服务端发送消息参数，如下图3所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-4b0d53de49c4265e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图3"></p>
<p>我们消息实体内仅添加了一个名称，我们一会会在前台界面将name字段的值传输到后台。</p>
<h4 id="服务端向浏览器发送的实体"><a href="#服务端向浏览器发送的实体" class="headerlink" title="服务端向浏览器发送的实体"></a>服务端向浏览器发送的实体</h4><p>下面我们再来创建一个服务端广播通知浏览器的实体类型，如下图4所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-a9b815556013a337.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图4"></p>
<p>上图4内仅一个消息内容返回到前台。我们通讯实体已经配置完成，下面我们开始编写通讯交互的控制器以及添加配置WebSocket的请求路径。</p>
<h4 id="配置WebSocket控制器"><a href="#配置WebSocket控制器" class="headerlink" title="配置WebSocket控制器"></a>配置WebSocket控制器</h4><p>我们添加一个名叫WsController的控制器并添加对应的@MessageMapping注解开启WebSocket的访问地址映射，如下图5所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-0c3e6219786b2820.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图5"></p>
<p>上图5内，当浏览器向服务端发送请求时，通过@MessageMapping映射/welcome这个地址，类似@RequestMapping，当服务端有消息存在时，会对订阅@SendTo中路径的浏览器发送请求。接下来我们添加一个Jsp页面来配置WebSocket的JS使用方式。</p>
<h4 id="配置JSP支持WebSocket"><a href="#配置JSP支持WebSocket" class="headerlink" title="配置JSP支持WebSocket"></a>配置JSP支持WebSocket</h4><p>在编写对应的代码之前，我们需要下载三个js文件，分别是：jquery.min.js、sockjs.min.js、stomp.min.js，在本章源码的resources/statis目录下（文章源码在本文最后）。Jsp代码如下图6所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-fcfe7a10ddac042d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图6"></p>
<p>我们在Jsp页面加载的时候先执行了一边关闭socket通道的操作，当我们点击《连接》按钮时会调用如下图7所示的Js方法完成开启连接操作：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-3c42e8557dca6cdd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图7"></p>
<p>可以看到我们通过SockJs来注册了endpoine，并且通过客户端开启通过连接，连接成功后调用setConnected方法来修改界面的元素显示隐藏，如下图8所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-4290ed5258605b0b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图8"></p>
<p>通过注册/topic/getReponse路径来回去服务端向浏览器端的请求数据内容，并且调用showResponse方法显示在页面中，showResponse方法如下图9所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-1d9b2e74c24f5220.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图9"></p>
<p>下面是断开连接的代码，如下图10所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-c6c742af17e7d6e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图10"></p>
<p>上面我们关于<code>WebSocket</code>的配置已经完成，我们需要访问对应的Jsp来测试，我们先修改<code>application.properties</code>配置文件添加<code>JSP</code>的路径映射，如下图11所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-08e754419b7d3df1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图11"></p>
<p>点击发送名称到后台的请求方法代码如下图12所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2d947f30446934d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图12"></p>
<p>可以看到我们发送内容直接到@MessageMapping的路径/welcome下。</p>
<h4 id="映射MVC到Index-jsp"><a href="#映射MVC到Index-jsp" class="headerlink" title="映射MVC到Index.jsp"></a>映射MVC到Index.jsp</h4><p>我们创建一个名叫做WebConfig的配置类并继承WebMvcConfigurerAdapter，实现addViewControllers方法添加对应的路径映射配置，如下图13所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-4ef84278d49b1e6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图13"></p>
<p>可以看到我们映射<code>/index</code>地址到<code>/index.jsp</code>也就是到<code>webapp/WEB-INF/jsp/index.jsp</code>，下面我们来启动项目测试效果。</p>
<h1 id="运行测试"><a href="#运行测试" class="headerlink" title="运行测试"></a>运行测试</h1><p>我们启动项目后，访问地址：<a href="http://127.0.0.1:8080/index" target="_blank" rel="noopener">127.0.0.1:8080/index</a>，界面输出内容如下图14所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-9424f9da4d78b115.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图14"></p>
<p>我们现在是断开连接的状态，我们尝试点击连接看下效果，如下图15所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2026cbd6df94c079.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图15"></p>
<p>可以看到我们成功的开启了WebSocket通道，开启通道后显示了对应的输入内容，我们来尝试输入一个名称点击发送查看界面输出内容如下图16所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-cbc8a09b2d40773e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图16"></p>
<p>点击《发送》按钮后等待3秒钟后，界面会输出欢迎的字样，证明我们的WebSocket通道已经成功的接通并且获取到了服务端返回到浏览器的数据，下面我们打开多个浏览器Tab来测试广播式的消息是否可以发送到多个开启WebSocket通道的浏览器中。</p>
<h1 id="测试广播式消息返回"><a href="#测试广播式消息返回" class="headerlink" title="测试广播式消息返回"></a>测试广播式消息返回</h1><p>我们先来打开浏览器中的多个Tab如下图17所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-5a8200485b1f4901.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图17"></p>
<p>上图17内的三个浏览器都开启了WebSocket通道，下面我们在其中一个浏览器中输出一个名称并点击《发送》按钮后，挨个浏览器查看效果，如下图18、19、20所示：<br><img src="http://upload-images.jianshu.io/upload_images/4461954-5019bdb93a5034b4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图18"><br><img src="http://upload-images.jianshu.io/upload_images/4461954-5011800d54eef813.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图19"><br><img src="http://upload-images.jianshu.io/upload_images/4461954-11eeff2cc0b0e701.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图20"></p>
<p>可以看到上三个图中，我们的WebSocket服务端通过广播的形式完成了服务端的消息发送到浏览器中。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>以上内容就是本章的全部内容，本章主要讲解了SpringBoot项目下如何配置使用WebSocket开启广播式消息发送，在以后的章节中我会添加点对点的形式。</p>
<p>本章源码已经上传到码云：</p>
<p>SpringBoot配套源码地址：<a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-boot-chapter</a></p>
<p>SpringCloud配套源码地址：<a href="https://gitee.com/hengboy/spring-cloud-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-cloud-chapter</a></p>
<p>SpringBoot相关系列文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a></p>
<p>QueryDSL相关系列文章请访问：<a href="http://www.jianshu.com/p/99a5ec5c3bd5" target="_blank" rel="noopener">QueryDSL通用查询框架学习目录</a></p>
<p>SpringDataJPA相关系列文章请访问：<a href="http://www.jianshu.com/p/615ed9c1fe84" target="_blank" rel="noopener">目录：SpringDataJPA学习目录</a></p>
<p>SpringBoot相关文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a>，感谢阅读！</p>
<p>欢迎加入QQ技术交流群，共同进步。<br><img src="http://upload-images.jianshu.io/upload_images/4461954-2e3ece62d204b1cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="QQ技术交流群"></p>

        
        </div>
        <footer class="article-footer">
            <div class="share-container">


    <div class="bdsharebuttonbox">
    <a href="#" class="bds_more" data-cmd="more">分享到：</a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
    <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
    <a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
</div>
<script>
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
</script>
<style>
    .bdshare_popup_box {
        border-radius: 4px;
        border: #e1e1e1 solid 1px;
    }
    .bdshare-button-style0-16 a,
    .bdshare-button-style0-16 .bds_more {
        padding-left: 20px;
        margin: 6px 10px 6px 0;
    }
    .bdshare_dialog_list a,
    .bdshare_popup_list a,
    .bdshare_popup_bottom a {
        font-family: 'Microsoft Yahei';
    }
    .bdshare_popup_top {
        display: none;
    }
    .bdshare_popup_bottom {
        height: auto;
        padding: 5px;
    }
</style>


</div>

            
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/spring-boot-chapter-21/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    第二十一章：SpringBoot项目中的全局异常处理
                
            </div>
        </a>
    
    
        <a href="/spring-boot-chapter-19/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">第十九章：使用JWT设计SpringBoot项目api接口安全服务</div>
        </a>
    
</nav>


    
</article>


    
    

</section>
            
			
				
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="no-thumbnail">
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-52/" class="title">第五十二章：基于SpringBoot2使用Rest访问MongoDB数据</a></p>
                            <p class="item-date"><time datetime="2018-04-21T16:00:00.000Z" itemprop="datePublished">2018-04-22</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-51/" class="title">第五十一章：基于SpringBoot2 &amp; MongoDB完成自动化集成</a></p>
                            <p class="item-date"><time datetime="2018-04-15T16:00:00.000Z" itemprop="datePublished">2018-04-16</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-50/" class="title">第五十章：SpringBoot2.0新特性 - 岂止至今最简单redis缓存集成</a></p>
                            <p class="item-date"><time datetime="2018-04-14T16:00:00.000Z" itemprop="datePublished">2018-04-15</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-49/" class="title">第四十九章：SpringBoot2.0新特性 - 你get到WebMvcConfigurer两种配置方式了吗？</a></p>
                            <p class="item-date"><time datetime="2018-03-16T16:00:00.000Z" itemprop="datePublished">2018-03-17</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-48/" class="title">第四十八章：SpringBoot2.0新特性 - RabbitMQ信任package设置</a></p>
                            <p class="item-date"><time datetime="2018-03-12T16:00:00.000Z" itemprop="datePublished">2018-03-13</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/QueryDSL-核心技术/">QueryDSL 核心技术</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a><span class="category-list-count">36</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">归档</h3>
        <div class="widget">
            <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">5</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签</h3>
        <div class="widget">
            <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/QueryDSL/">QueryDSL</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SpringBoot/">SpringBoot</a><span class="tag-list-count">43</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/tags/QueryDSL/" style="font-size: 10px;">QueryDSL</a> <a href="/tags/SpringBoot/" style="font-size: 20px;">SpringBoot</a>
        </div>
    </div>

    
        
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
                    <li>
     				<a href="http://hexo.io" target="_blank">Hexo</a>
					</li>
                
            </ul>
        </div>
    </div>


    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

				
        </div>
        <!--引入不蒜子-->
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            <span  id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
            &copy; 2017 - 2018 恒宇少年 - 版权所有<br>
        </div>
    </div>
</footer>

        


    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>